<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function login(){
    	$this->display();
    }

    public function index_superadmin(){
    	$this->display();
    }

    public function index_clubadmin(){
    	$this->display();
    }

    public function checkLogin(){
        session('flag',null);
        $code=I('post.verify');

        if(!$this->check_verify($code))$this->error('验证码错误');

        $admin=M('admins');
        $map   =   array();
        $map['admin_name']	= trim(I('post.username'));
        $map['password']	= trim(I('post.password'));
        $per=trim(I('post.admin_flag'));

        $res=$admin->where($map)->select();
        if($res==null){
            $this->error('用户名密码错误');
        }else {
            if($per==1){
            session("flag","logok");
            redirect('http://localhost/neu1_yuejian/index.php/Admin/Index/index_superadmin');}
            else{ redirect('http://localhost/neu1_yuejian/index.php/Admin/Index/index_clubadmin');}
        }
    }
    public function _initialize(){
        //只要不是显示登录页面和处理登录、验证码这些，其他情况都要进行session验证。
        if(ACTION_NAME!='index' && ACTION_NAME!='checkLogin'&& ACTION_NAME!='verify'){
            //redirect('index');
        }
    }

    function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }


    public function count()
    {
        $this->count1 = M('users')->count();
        $this->count2 = M('lost')->count();
        $this->count3 = M('find')->count();
        $this->count4 = M('goods')->count();
        $this->display();
    }
    public function verify(){
        ob_clean();
        $Verify = new \Think\Verify();
        $Verify->entry();

    }
}